var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ModuleMgr = undefined;
var BundleConfig = require("AA_BundleConfig");
var EventManager = require("AA_EventManager");
var SingletonManager = require("AA_SingletonManager");
var ResLoader = require("AA_ResLoader");
var ResUtil = require("AA_ResUtil");
var EvenType = require("AA_EvenType");
var BaseModule = require("AA_BaseModule");
var f = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._modules = new Map();
    t._isLoadingTime = false;
    return t;
  }
  __extends(t, e);
  t.prototype.show = function (e, t, o) {
    undefined === o && (o = {});
    return __awaiter(this, undefined, undefined, function () {
      var n;
      var i;
      var a;
      return __generator(this, function (r) {
        switch (r.label) {
          case 0:
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Load_View, true);
            if (this._isLoadingTime) {
              return [2];
            } else {
              n = null;
              this._isLoadingTime = true;
              if (this._modules.has(e)) {
                return [3, 2];
              } else {
                i = "module/" + e;
                return [4, ResLoader.default.loadRes(BundleConfig.BundleNames.Home, 'home/'+i, cc.Prefab)];
              }
            }
          case 1:
            a = r.sent();
            n = ResUtil.ResUtil.instantiate(a);
            t.addChild(n);
            n.getComponent(BaseModule.default).show(o);
            this._modules.set(e, n);
            return [3, 3];
          case 2:
            n = this._modules.get(e);
            r.label = 3;
          case 3:
            this._modules.forEach(function (e) {
              e.active = e == n;
            });
            this._isLoadingTime = false;
            EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.Game_Load_View, false);
            return [2];
        }
      });
    });
  };
  t.prototype.cleanModule = function () {
    this._modules.clear();
  };
  return t;
}(SingletonManager.SingletonMgr);
exports.ModuleMgr = f.getInstance();